﻿using UnityEngine;
using System.Collections;
namespace FSM
{
    /// <summary>
    /// 逻辑判断节点
    /// </summary>
    public class IfNode:Condition
    {
        private Condition condition;
        private Action actionTrue;
        public IfNode(Condition coditi,Action action)
        {
            this.condition = coditi;
            this.actionTrue = action;
        }
        public override void Init(params object[] param)
        {
            int l = param.Length;
            if(l > 0)
            {
                var cod = param[0] as Condition;
                condition = cod;
            }
            if(l > 1)
            {
                var ac = param[1] as Action;
                actionTrue = ac;
            }
        }
        protected override bool OnUpdate()
        {
            if(condition != null && condition.Update())
            {
                if(actionTrue != null)
                {
                    actionTrue.Update();
                }
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
